﻿using StableDiffusionTools.Framework;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using TaggingToolkit.Framework;

namespace TaggingToolkit.Framework
{
    public class TaggingToolkitSettings : Settings
    {
        public ClipType ClipType { get; set; } = ClipType.DeepBooru;
        public int MaxFileReadThreads { get; set; } = 4;
        public int MaxWorkerThreads { get; set; } = 4;
        public string LastPath { get; set; } = "";
        public bool quitConfirmation = true;
        public bool saveConfirmation = true;
        public bool loadConfirmation = true;
        public bool createConfirmation = true;
        public bool FitSize { get; set; } = true;
        public int WebUIPort { get; set; } = 7860;
        public bool DisplayImageThumbnails { get; set; } = true;
        public bool FitFileColumnToThumbnails { get; set; } = true;
        public bool PrecacheImageThumbnails { get; set; } = false;
        public int PreviewSize { get; set; } = 64;
        public List<Size> LetterboxSizes = null;
        public List<Size> FinalSizes = null;
        public double LastZoom = 1.0;
        public Size LastLetterboxSelection = new Size(512, 512);
        public Size LastFinalSizeSelection = new Size(512, 512);
        public int LastSidePanelWidth { get; set; } = -1;
        public int LastSidePanelHeight { get; set; } = -1;
        [XmlElement(Type = typeof(XmlColor))]
        public Color LetterboxColor { get; set; } = Color.FromArgb(175, Color.Black);
        [XmlElement(Type = typeof(XmlColor))]
        public Color SearchReplaceInsertColor { get; set; } = Color.LightGreen;
        [XmlElement(Type = typeof(XmlColor))]
        public Color SearchReplaceRemoveColor { get; set; } = Color.IndianRed;

        public void ResetConfirmationPrompts()
        {
            quitConfirmation = true;
            saveConfirmation = true;
            loadConfirmation = true;
            createConfirmation = true;
        }

        public override void EndInit()
        {
            if (LetterboxSizes == null)
                LetterboxSizes = new List<Size>(new Size[] { new Size(512, 512), new Size(512, 768), new Size(768, 512), new Size(768, 768), new Size(768, 1024), new Size(1024, 768), new Size(1024, 1024) });

            LetterboxSizes.Sort((i1, i2) => (i1.Width * i1.Height).CompareTo(i2.Width * i2.Height));

            if(FinalSizes == null)
                FinalSizes = new List<Size>(new Size[] { new Size(512, 512), new Size(512, 768), new Size(768, 512), new Size(768, 768), new Size(768, 1024), new Size(1024, 768), new Size(1024, 1024) });

            FinalSizes.Sort((i1, i2) => (i1.Width * i1.Height).CompareTo(i2.Width * i2.Height));
        }
    }
}
